﻿using DomainModel;
using Microsoft.Practices.Unity;
using MusicManager.BL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    public static class Database
    {
        [Dependency]
        public static IMusicManagerBL Logic { get; set; }
        
        public static void Init(IMusicManagerBL bl)
        {
            Logic = bl;
            string token;
            bool success = false;
            success = Logic.CreateUser(1, "Michael", "asdf");
            Console.WriteLine(success ? "Created User Michael" : "User Michael already created");
            success = Logic.Login("Michael", "asdf", out token);
            Console.WriteLine(success ? "User Michael logged in" : "Cant log in as Michael");

            byte[] buffer;
            using (var fileStream = new FileStream(@"D:\Programme\DropBox\Dropbox\ML\CLC\Data\Foster The PeopleHoudini.mp3", FileMode.Open))
            {
                buffer = new byte[fileStream.Length];
                fileStream.Read(buffer, 0, (int)fileStream.Length);               
            }

            success = Logic.AddMusic("ka4", buffer, token);
            Console.WriteLine(success ? "Added Song ka" : "Error Adding Song");

            IEnumerable<string> playlist = Logic.GetPlaylist(token);
            Console.WriteLine("Playlist of michael:");
            foreach (var music in playlist)
            {
                Console.WriteLine(music);
            }

            Music songOutput = Logic.GetMusic("ka4", token);           
        }
    }
}
